package com.test.ml.base;

import com.test.ml.yqs.entity.TqzTask;
import com.test.ml.yqs.service.TqzTaskService;
import com.test.ml.yqs.utills.ResultJson;
import com.test.ml.yqs.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 马亮
 * @version V1.0
 * @Description: TODO
 */
public abstract class BaseController<TDto extends BaseEntity, TService extends BaseService> {

    @Autowired
    private TService service;

    /**
     * 查询
     * @param page
     * @return
     */
    @RequestMapping(value = "list" ,method = RequestMethod.POST)
    public ResultJson tasklist(@RequestBody TDto entity, Page page){
        return service.queryList(entity,page);
    }

    /**
     * 新增
     * @param task
     * @return
     */
    @RequestMapping(value="addOrUpdate",method = RequestMethod.POST)
    public ResultJson addTask(@RequestBody TDto task){
        if(StringUtils.isEmpty(task.getId())){
            return service.add(task);
        }else{
            return service.update(task);
        }


    }

    @RequestMapping(value="del",method = RequestMethod.POST)
    public ResultJson deleteTask(@RequestParam String ids){
        String[] id=ids.split(",");
        return service.delete(id);
    }
}